package com.abe.bathsystem.contract.presenter;

import com.abe.bathsystem.contract.CommonContract;
import com.abe.bathsystem.contract.CommonModel;
import com.abe.bathsystem.entity.ReqBaseEntity;
import com.abe.bathsystem.entity.ReqConstant;
import com.abe.bathsystem.entity.http.HttpVersionEntity;
import com.abe.mvpcore.BasePresenter;
import com.abe.mvpcore.OnResultListener;

public class VersionPresenter extends BasePresenter<CommonContract.VersionView, CommonModel> implements CommonContract.VersionPresenter {
    @Override
    public void checkVersion(final boolean isAutoUpdate) {
        getModel().checkVersion(new OnResultListener<ReqBaseEntity<HttpVersionEntity>>() {
            @Override
            public void onStart() {

            }

            @Override
            public void onEnd() {
                VersionPresenter.this.onEnd(ServerPresenter.class.getSimpleName());
            }

            @Override
            public void onSuccess(ReqBaseEntity<HttpVersionEntity> data) {
                if (VersionPresenter.this.onSuccess(data)) {
                    getView().onCheckVersion(data.getCode() == ReqConstant.NET_RESULT_OK,isAutoUpdate, data.getData());
                }
            }

            @Override
            public void onFailure(String message) {
                VersionPresenter.this.onFailure(ServerPresenter.class.getSimpleName());
            }
        });
    }
}
